package pap.initialization;

import java.util.ArrayList;
import java.util.List;

import pap.Point;
import pap.Vector;
import pap.bodies.Body;
import pap.bodies.SimpleBody;
import pap.utils.Constants;
import pap.utils.UtilMethods;


public class RandomBodyInitializer implements IBodyInitializer {

	@Override
	public List<Body> initAndGetBodies() {
		List<Body> bodies = new ArrayList<Body>();
		int bodiesNumber = Constants.BODIES_NUMBER;

		for (int i = 0; i < bodiesNumber; i++)
			bodies.add(genRandomSimpleBody());

		return bodies;
	}
	
	/**
	 * Generates a random body.
	 * 
	 * @return a SimpleBody
	 */
	private SimpleBody genRandomSimpleBody() {

		double mass = UtilMethods.getRandomDouble(Constants.MIN_MASS,
				Constants.MAX_MASS);

		Point position = UtilMethods.getRandom2DPoint(Constants.MIN_START_X,
				Constants.MAX_START_X, Constants.MIN_START_Y,
				Constants.MAX_START_Y);

		Vector speed = UtilMethods.getRandom2DVector(Constants.MIN_START_SPEED,
				Constants.MAX_START_SPEED);

		return new SimpleBody(mass, position, speed);
	}
}
